//
//  BYBaseViewController.m
//  OCDemo
//
//  Created by 朱慕之 on 2022/1/2.
//

#import "BYBaseViewController.h"

@interface BYBaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation BYBaseViewController


#pragma mark - Init

- (instancetype)init {
    self = [super init];
    if (self) {
        self.navigationType = BYNavigationTypeShow;
    }
    return self;
}

- (instancetype)initWithNavigationType:(BYNavigationType)type {
    self = [self init];
    if (self) {
        self.navigationType = type;
    }
    return self;
}
 

#pragma mark - LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 默认背景颜色
    self.view.backgroundColor = BACKGROUND_VIEW_COLOR;
    
    // 滚动之后导航栏颜色不更改
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appearnce = [[UINavigationBarAppearance alloc] init];
        [appearnce configureWithOpaqueBackground];
        appearnce.backgroundColor = BACKGROUND_VIEW_COLOR;
        self.navigationController.navigationBar.standardAppearance = appearnce;
        self.navigationController.navigationBar.scrollEdgeAppearance = appearnce;
    }

    // iOS11版本适配
//    if (@available(iOS 11.0, *)) {
//        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
//    } else {
//        self.automaticallyAdjustsScrollViewInsets = NO;
//    }
//
    // 显示导航栏
    if (self.navigationType == BYNavigationTypeShow) {
        [self setNavigationBarImage:[UIImage imageWithColor:NAVIGATION_BAR_COLOR]];
    }
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.navigationType == BYNavigationTypeShow) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self setNavigationBarImage:[UIImage imageWithColor:NAVIGATION_BAR_COLOR]];
    } else{
        [self.navigationController setNavigationBarHidden:YES animated:YES];
//        [self.view bringSubviewToFront:self.customNaviView];
    }
    
    // iOS 13相关适配
//    if (@available(iOS 13.0, *)) {
//        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
//    } else {
//        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

#pragma mark - Private Method

// 设置导航Bar图片-背景颜色
- (void)setNavigationBarImage:(UIImage* )image {
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
        UIImage *image1 = [image resizableImageWithCapInsets:UIEdgeInsetsMake(2, 1, 2, 1)];
        [self.navigationController.navigationBar setBackgroundImage:image1 forBarMetrics:UIBarMetricsDefault];
        self.navigationController.navigationBar.shadowImage = [UIImage new];
    }
}


/**
 * 导航左侧按钮-点击事件
 */
- (void)leftButtonMethod {
//    if (self.isPresent) {
//        [self dismissViewControllerAnimated:YES completion:nil];
//    }
//    else{
//        [self.navigationController popViewControllerAnimated:YES];
//    }
}

/**
 * 导航右侧按钮-点击事件
 */
- (void)rightButtonMethod {
    
}





@end
